home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / DOPUSJPEG / Pic2Jpeg.dopus5 < prev    next >
Text File  |  1996-01-12  |  3KB  |  115 lines

  1. /* Pic TO JPEG COMPRESSOR v1.0 [03-jan-96] for Directory Opus 5
  2.    By Christophe NOWAK
  3.  
  4.    Need the JPEGVxBin Package with cjpeg and djpeg
  5.    ilbmtoppm needed for IFF Pictures.
  6.    pcxtoppm needed for PCX Pictures.
  7.  
  8.    TODO : Support of PhotoCD and other formats
  9.  
  10. */
  11.  
  12. parse arg portname tmpdir option .
  13.  
  14. options results
  15. if portname='' then
  16.   portname='DOPUS.1'
  17. address value portname                  
  18.  
  19. lister query source
  20. if rc>0 then do
  21.   dopus request '"Error - No source files" ok'
  22.   call end_script
  23. end
  24.  
  25. parse var result handle .
  26.  
  27. lister set handle busy on
  28.  
  29. lister query handle path
  30. if rc>0 then
  31.   call end_script
  32. chemin=result
  33.  
  34. lister query handle selfiles stem files.
  35.  
  36. if files.count=0 then do
  37.   dopus request '"Error - No source files" ok'
  38.   call end_script
  39. end
  40.  
  41. dopus getstring '"Enter Compression Quality" 3 "" Ok'
  42. comp_quality=RESULT
  43. if LENGTH(comp_quality)=3 then do
  44.     dopus request '"Error - Quality must be < 100" ok'
  45.     call end_script
  46. end
  47.  
  48. lister set handle progress files.count 'Compressing Pictures...'
  49. lister set handle title 'Compressing Pictures...'
  50. lister refresh handle full
  51.  
  52. do i=0 to files.count-1
  53.   lister query handle abort
  54.   if result then
  55.     call end_script
  56.  
  57.   lister set handle progress count i+1
  58.   lister set handle progress name files.i
  59.   lister query handle entry files.i stem fileinfo.
  60.  
  61.   workfile='"'chemin||fileinfo.name'"'
  62.   if tmpdir=''|tmpdir='""' then
  63.     tmpfile='"'chemin||fileinfo.name||.tmp'"'
  64.   else tmpfile='"'tmpdir||fileinfo.name||.tmp'"'
  65.  
  66.   ext=reverse(fileinfo.name)            
  67.   parse var ext ext '.'
  68.   ext=upper(reverse(ext))
  69.  
  70.   if ext='JPG'|ext='JPEG'|ext='JFIF' then do
  71.     destfile='"'chemin||fileinfo.name||.jpg'"'
  72.     address command 'djpeg -outfile' tmpfile workfile 
  73.     call Compress_File
  74.   end
  75.  
  76.   if ext='GIF'|ext='TGA'|ext='TARGA'|ext='PPM'|ext='PBM' then do
  77.     parse var fileinfo.name truncfile '.'
  78.     destfile='"'chemin||truncfile||.jpg'"'
  79.     address command 'cjpeg -optimize -quality' comp_quality option workfile '>'destfile
  80.   end
  81.  
  82.   if ext='IFF'|ext='ILBM' then do
  83.     parse var fileinfo.name truncfile '.'
  84.     destfile='"'chemin||truncfile||.jpg'"'
  85.     address command 'ilbmtoppm' workfile '>'tmpfile
  86.     call Compress_File
  87.   end
  88.  
  89.   if ext='PCX' then do
  90.     parse var fileinfo.name truncfile '.'
  91.     destfile='"'chemin||truncfile||.jpg'"'
  92.     address command 'pcxtoppm' workfile '>'tmpfile
  93.     call Compress_File
  94.   end
  95.  
  96.   lister select handle '"'fileinfo.name'"' off
  97.   lister refresh handle full
  98. end
  99.  
  100. call end_script
  101.  
  102. Compress_File:
  103.   address command 'cjpeg -optimize -quality' comp_quality option tmpfile '>'destfile
  104.   address command 'delete' tmpfile
  105.   return
  106.  
  107. Error:
  108.   dopus request '"Error in command - Sorry" ok'
  109.  
  110. end_script:
  111.   lister set handle title
  112.   lister refresh handle full
  113.   lister set handle busy off
  114.   EXIT
  115.